using System;
using System.Data;
using System.Collections.Generic;

namespace shfa.snomtastic.data.business
{
    public partial class PhoneController
    {
		private PhoneInfo ObjectFromDataRow(DataRow dr)
        {
            if (dr != null)
            {
				PhoneInfo obj = new PhoneInfo();
				obj.PhoneId = dr.Field<Guid>("PhoneId"); 
				obj.MacAddress = dr.Field<String>("MacAddress"); 
				obj.UserId = (dr["UserId"] != DBNull.Value) ? dr.Field<Guid>("UserId") : Guid.Empty; 
				obj.ConfigurationId = (dr["ConfigurationId"] != DBNull.Value) ? dr.Field<Guid>("ConfigurationId") : Guid.Empty; 
				obj.IpAddress = (dr["IpAddress"] != DBNull.Value) ? dr.Field<String>("IpAddress") : string.Empty; 
				obj.SubnetId = (dr["SubnetId"] != DBNull.Value) ? dr.Field<Guid>("SubnetId") : Guid.Empty; 
				obj.SerialNumber = (dr["SerialNumber"] != DBNull.Value) ? dr.Field<String>("SerialNumber") : string.Empty; 
				obj.UserAgent = (dr["UserAgent"] != DBNull.Value) ? dr.Field<String>("UserAgent") : string.Empty; 
				obj.ModelId = (dr["ModelId"] != DBNull.Value) ? dr.Field<Guid>("ModelId") : Guid.Empty; 
				obj.Model = (dr["Model"] != DBNull.Value) ? dr.Field<String>("Model") : string.Empty; 
				obj.FirmwareId = (dr["FirmwareId"] != DBNull.Value) ? dr.Field<Guid>("FirmwareId") : Guid.Empty; 
				obj.Firmware = (dr["Firmware"] != DBNull.Value) ? dr.Field<String>("Firmware") : string.Empty; 
				obj.BootLoader = (dr["BootLoader"] != DBNull.Value) ? dr.Field<String>("BootLoader") : string.Empty; 
				obj.Extension = (dr["Extension"] != DBNull.Value) ? dr.Field<String>("Extension") : string.Empty; 
				obj.FirstFailedDate = (dr["FirstFailedDate"] != DBNull.Value) ? dr.Field<DateTime>("FirstFailedDate") : DateTime.MinValue; 
				obj.RegistrationFailed = dr.Field<Boolean>("RegistrationFailed"); 
				obj.ReRegisterCount = dr.Field<Int32>("ReRegisterCount"); 
				obj.HttpClientPass = (dr["HttpClientPass"] != DBNull.Value) ? dr.Field<String>("HttpClientPass") : string.Empty; 
				obj.CreatedDate = dr.Field<DateTime>("CreatedDate"); 
				obj.UpdatedDate = dr.Field<DateTime>("UpdatedDate"); 
				return obj;
            }
            return null;
        }

        private List<PhoneInfo> ListFromDataTable(DataTable dt)
        {
            List<PhoneInfo> lst = new List<PhoneInfo>();

            foreach (DataRow dr in dt.Rows)
            {
                lst.Add(ObjectFromDataRow(dr));
            }

            return lst;
        }
    }
}
